import pygame
import random
from pygame.sprite import Sprite


class Alien(Sprite):
    """外星人类"""

    def __init__(self, ai_game):
        """初始化外星人并设置位置"""
        super().__init__()
        self.screen = ai_game.screen
        self.settings = ai_game.settings
        # 加载外星人图片，设置rect
        self.image = pygame.image.load(
            "PythonPrograming/project/alien_invasion/images/alien.bmp")
        self.rect = self.image.get_rect()
        # 初始化外星人的坐标
        self.rect.x = random.randint(
            0, self.settings.screen_width - self.rect.width)
        self.rect.y = 0
        self.x = float(self.rect.x)

    def update(self):
        """向右移动外星人"""
        self.x += (self.settings.alien_speed * self.settings.fleet_direction)
        self.rect.x = self.x

    def check_edges(self):
        """如果有外星人位于屏幕边缘，就返回True"""
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right or self.rect.left <= 0:
            return True


if __name__ == '__main__':
    print(Alien.__init__.__doc__)
